﻿<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>应用设置</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
  <link rel="stylesheet" href="/plugins/layui/css/layui.css" media="all">
  <script type="text/javascript" src="/plugins/codemirror/js/codemirror.js"></script>
  <style type="text/css">
        .CodeMirror-line-numbers {
            width: 2.2em;
            color: #aaa;
            background: #f5f5f5;
            text-align: right;
            padding: 0px .3em 0 0;
            font: 12px/16px Consolas,"Courier New",monospace;
        }
        .clearfix {
            zoom: 1;
        }
        .template-editer {
            float: left;
            width: 100%;
        }
        .editer-toolbar {
            padding: 5px;
            border: 1px solid #ccc;
            border-bottom: 0;
            background: #eee;
        }
        .editer-toolbar input.button {
            font-size: 12px;
            border: 0;
            height: 20px;
            padding: 0 0 0 16px;
            background-color: transparent;
            background-repeat: no-repeat;
            background-position: 0 50%;
        }
        .editer-area {
            margin: 0 0 5px 0;
            border: 1px solid #ccc;
            background: #fff;
        }
    </style>
</head>
<body>
  <div class="layui-form" lay-filter="form-add" id="form-add">
    <input type="hidden" name="id" id="id" value="" />
    <div class="layui-form-item">
      <div class="editer-col1">
        <div class="clearfix editer-toolbar">
            <input class="button" type="button" value="保存修改" lay-submit lay-filter="btn_save" id="btn_save" style="background-image: url(/admin/statics/images/save.gif);" />
            <span style="margin-left:10px;color:#ff0000;"> 温馨提示：以下为应用的敏感配置信息，请谨慎更改。</span>
        </div>
        <div class="editer-area" style="overflow-y: hidden;overflow-x: hidden;">
            <textarea rows="28" style="width: 100%;height:450px;" name="content" id="content"></textarea>
        </div>
      </div>
    </div>
    <div class="layui-form-item layui-hide">
      <input type="button" lay-submit lay-filter="btn_submit" id="btn_submit" value="确定">
    </div>
  </div>
  <script src="/plugins/layui/layui.js"></script>
  <script type="text/javascript" src="/plugins/common/login.js"></script>
  <script>
    layui.config({
    base: '/plugins/layuiadmin/' 
    }).extend({
    index: 'lib/index'
    }).use(['index', 'form'], function(){
    var $ = layui.$, form = layui.form, router = layui.router();
    layer.load();
    $.ajax({
        type: "get",
        url: "app_set",
        data: router.search,
        async:false, 
        dataType: "json",
        success: function (res) {
            if (res.code == 0)
            {
                $("#id").val(router.search.id);
                $("#content").text(res.data);
            }
            else if (res.code == 110)
            {
                layer.closeAll('loading'); 
                layer.alert(res.msg, function () {
                    ReLogin();
                });
            }
            else
            {
                layer.closeAll('loading'); 
                layer.alert(res.msg);
            }
        }
    });

    var editor = CodeMirror.fromTextArea('content', {
        containerID: 'TheEditor',
        lineNumbers: true,
        textWrapping: false,
        path: "/plugins/codemirror/js/",
        parserfile: ['parsexml.js', 'parsecss.js', 'tokenizejavascript.js', 'parsejavascript.js', 'parsehtmlmixed.js'],
        stylesheet: ['/plugins/codemirror/css/xmlcolors.css', '/plugins/codemirror/css/jscolors.css', '/plugins/codemirror/css/csscolors.css']
    });

    layer.closeAll('loading'); 

    form.on('submit(btn_save)', function (data) {
        layer.load();
        var field = data.field; //获取提交的字段
        field.content = editor.getCode();
        $.ajax({
            type: "post",
            url: "app_set",
            data: field,
            dataType: "json",
            success: function (res) {
                layer.closeAll('loading');
                if (res.code == 0)
                {
                  layer.msg(res.msg,{time:1*1000},function(){
                     parent.GetFirstList();
                   });
                }
                else if (res.code == 110)
                {
                    layer.alert(res.msg, function () {
                        ReLogin();
                    });
                }
                else
                {
                    layer.alert(res.msg);
                }
            }
        });
    });

    form.on('submit(btn_submit)', function (data) {
        layer.load();
        var field = data.field; //获取提交的字段
        var index = parent.layer.getFrameIndex(window.name); 
        field.content = editor.getCode();
        $.ajax({
            type: "post",
            url: "app_set",
            data: field,
            dataType: "json",
            success: function (res) {
                layer.closeAll('loading'); 
                if (res.code == 0)
                {
                     layer.msg(res.msg,{time:1*1000},function(){
                         parent.layer.close(index); //再执行关闭 
                         parent.GetFirstList();
                     });
                }
                else if (res.code == 110)
                {
                    layer.alert(res.msg, function () {
                        ReLogin();
                    });
                }
                else
                {
                    layer.alert(res.msg);
                }
            }
        });
    });
    })
  </script>
</body>
</html>